/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');

    var toastr =require('toastr');

    app.useModule("ui.table");


    var datepicker = require('datepicker');
    app.controller('debt_listCtrl', ['$scope','$http','$filter' ,function ($scope, $http,$filter) {
        $scope.ctrlScope=$scope;
        $scope.orderParams = {
            url: "/admin/debt/getDebtList"
        };
        datepicker($scope);
        //全局查询
        $scope.search = function() {
            $scope.ctrlScope.itemsearch.beginDate= $scope.ctrlScope.itemsearch.beginDateTimex;
            $scope.ctrlScope.itemsearch.endDate= $scope.ctrlScope.itemsearch.endDateTimex;
            $scope.ctrlScope.itemsearch.beginDate=$filter('date')($scope.ctrlScope.itemsearch.beginDate,'yyyy-MM-dd');
            $scope.ctrlScope.itemsearch.endDate=$filter('date')($scope.ctrlScope.itemsearch.endDate,'yyyy-MM-dd');
            //表格查询参数设置
            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;
            //表格刷新
            $scope.orderParams.reload();
        };
        //全局查询重置
        $scope.reset=function(){
            $scope.orderParams.ajaxParam={};
            $scope.ctrlScope.itemsearch={};
            $scope.orderParams.reload();
        };
        //导出
        $scope.download=function(){
            var params=$scope.ctrlScope.itemsearch;
            $http.post("/admin/invest/excel/invest",params)
                .success(function (data){
                    if(data.result=="success"){
                        window.open(data.file);
                    }else{
                        toastr.error("导出失败");
                    }
                }).error(function(data){

                });
        };
        //查看
        $scope.modifyModal=function(id,itemId){
            $scope.orderParams2.ajaxParam = {debtId: id}
            $scope.orderParams2.reload();
            $scope.showDiv = !$scope.showDiv;
            //债权基本信息
            $http({
                method: 'POST',
                url: "/admin/debt/getDebtById",
                data: {
                    id:id
                }
            }).success(function(data){
                $scope.list=data;
                $scope.listType=data.type;
                if($scope.listType==0){
                    $scope.listType="未债权";
                }else if($scope.listType==1){
                    $scope.listType="已债权";
                }else if($scope.listType==2){
                    $scope.listType="已过期";
                }

                $scope.listStatus=data.status;
                if($scope.listStatus==1){
                    $scope.listStatus="个人发布";
                }else if($scope.listStatus==2){
                    $scope.listStatus="企业发布";
                }

            })
        }
        //债权投资记录
        $scope.orderParams2 = {
            url: "/admin/debtInvest/getDebtInvestList",
        };
        //下载合同
        $scope.getContract=function(url){
            if(url){
                window.open(url);
            }else{
                toastr.error("下载失败");
            }
        };
    }]);


});